<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>

  <body>
    <!-- <script>
      var data = [
        {
          id: 1,
          name: "家电",
          goods: [
            {
              id: 11,
              gname: "冰箱",
              goods: [
                {
                  id: 111,
                  gname: "海尔冰箱",
                },
                {
                  id: 112,
                  gname: "小天鹅冰箱",
                },
              ],
            },
            {
              id: 12,
              gname: "洗衣机",
            },
          ],
        },
        {
          id: 2,
          name: "服饰",
        },
      ];

      function fn(data, id) {
        var good = {};
        data.forEach(function (item) {
          //console.log(item);
          if (item.id === id) {
            console.log(item);
          } else if (item.goods && item.goods.length > 0) {
            good = fn(item.goods, id);
          }
        });
        return good;
      }

      console.log(fn(data, 12));

      function fn1(a, b) {
        console.log(a); // 1,undefined
        console.log(b); //undefined
        var b = 234;
        console.log(b); //234
        a = 123;
        console.log(a); //123

        function a() {}
        var a;
        b = 234;
        var b = function () {};
        console.log(a); // f(){}
        console.log(b); //undefined
      }
      fn1(1);

      a = 100;

      function fn2(e) {
        function e() {}
        arguments[0] = 2;
        console.log(e); //2
        if (a) {
          var b = 123;
        }
        var c;
        a = 10;
        var a;
        console.log(b); //undefined
        f = 123;
        console.log(c); //undefined
        console.log(a); //10
      }
      var a;
      fn2(1);
      console.log(a); // 100
      console.log(f); // 123

      arr = [1, 1, 3];
    </script> -->
  </body>
</html>
